from langchain_core.prompts import PromptTemplate
from langchain_openai import ChatOpenAI
import streamlit as st
from langchain_core.messages import HumanMessage, SystemMessage

st.title('Talk to LLM:')

llm = ChatOpenAI(
  openai_api_key="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",
  openai_api_base="https://openrouter.ai/api/v1",
  model_name="qwen/qwq-32b:free"
)
if "messages" not in st.session_state:
    st.session_state["messages"]=[]

question = st.text_input("question:", key="question")

if question:
    st.session_state["messages"].append(HumanMessage(question))

    response =llm.invoke(st.session_state['messages'])
    st.write(response.content)
    
    st.session_state['messages'].append(response)
    
    st.title("Messages List:")
    line = 1
    for mes in st.session_state['messages']:
        if line%2 == 1:
          st.write("question: "+ mes.content)
        else:
          st.write("answer: "+ mes.content)
        line = line + 1
    #st.session_state['question'] = ""

